﻿using System;

namespace Testing.Helpers.Extensions
{
    /// <summary>
    /// Extensions for DateTime?.
    /// </summary>
    public static class DateTimeExtension
    {
        /// <summary>
        /// Checks for the equality of another date.
        /// </summary>
        /// <param name="dateTime">Current date.</param>
        /// <param name="otherDateTime">Another date.</param>
        /// <returns>Equality of two dates.</returns>
        public static bool EqualsTo(this DateTime? dateTime, DateTime? otherDateTime)
        {
            bool equals;
            if (dateTime.HasValue)
            {
                equals = (otherDateTime.HasValue) && dateTime.Value.Date.Equals(otherDateTime.Value.Date);
            }
            else
            {
                equals = (!otherDateTime.HasValue);
            }
            return equals;
        }

        /// <summary>
        /// Gets a string representation of a date, depending on having value.
        /// </summary>
        /// <param name="dateTime">Date.</param>
        /// <param name="provider">Format provider.</param>
        /// <returns>String representation of a date.</returns>
        public static string GetString(this DateTime? dateTime, IFormatProvider provider)
        {
            return (dateTime.HasValue) ? dateTime.Value.Date.ToString(provider) : String.Empty;
        }

    }

    
}
